package View.Updata;

import Hander.Add.AddProjectPersonnelViewHander;
import Hander.Updata.UpdataProjectPersonnelViewHander;
import View.LeaderView;
import entity.Achievement;
import entity.ProjectPersonnelTable;
import service.PersonnelService;
import service.PersonnelServiceImpl;

import javax.swing.*;
import java.awt.*;
import java.sql.Date;
import java.util.Vector;

public class UpdataProjectPersonnelView extends JDialog {
    private String tableName="projectpersonneltable";
    private JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));


    //JLabel projectpersonnelIDLabel = new JLabel("projectpersonnelIDLabel:", JLabel.RIGHT);
    //JTextField projectpersonnelIDField = new JTextField();

    JLabel projectIDLabel = new JLabel("projectID:", JLabel.RIGHT);
    JTextField projectIDField = new JTextField();
    JLabel personnelIDLabel = new JLabel("personnelID:", JLabel.RIGHT);
    JTextField personnelIDField = new JTextField();
    JLabel roleLabel = new JLabel("role:", JLabel.RIGHT);
    JTextField roleField = new JTextField();
    JLabel startDateLabel = new JLabel("startDate:", JLabel.RIGHT);
    JTextField startDateField = new JTextField();
    JLabel endDateLabel = new JLabel("endDate:", JLabel.RIGHT);
    JTextField endDateField = new JTextField();
    JButton updataBtn = new JButton("修改");
    UpdataProjectPersonnelViewHander updataProjectPersonnelViewHander;

    public UpdataProjectPersonnelView(LeaderView leaderView, int key) {
        super(leaderView, "添加部门信息", true);
        PersonnelService personnelService=new PersonnelServiceImpl();
        Vector<Object> array = personnelService.getBy(key, "projectpersonneltable");


        updataProjectPersonnelViewHander = new UpdataProjectPersonnelViewHander(this, leaderView);


        projectIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(projectIDLabel);
        projectIDField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(projectIDField);
        projectIDField.setText(""+array.get(1));


        personnelIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(personnelIDLabel);
        personnelIDField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(personnelIDField);
        personnelIDField.setText(""+array.get(2));

        roleLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(roleLabel);
        roleField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(roleField);
        roleField.setText(""+array.get(3));

        startDateLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(startDateLabel);
        startDateField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(startDateField);
        startDateField.setText(""+array.get(4));

        endDateLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(endDateLabel);
        endDateField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(endDateField);
        endDateField.setText(""+array.get(5));


        updataBtn.addActionListener(updataProjectPersonnelViewHander);
        jPanel.add(updataBtn);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        setSize(400, 350);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public ProjectPersonnelTable buildDepartment() {
        ProjectPersonnelTable projectPersonnelTable = new ProjectPersonnelTable();
        projectPersonnelTable.setProjectPersonnelID(0);
        projectPersonnelTable.setProjectID(Integer.valueOf(projectIDField.getText()));
        projectPersonnelTable.setPersonnelID(Integer.valueOf(personnelIDField.getText()));
        projectPersonnelTable.setRole(roleField.getText());
        projectPersonnelTable.setStartDate(Date.valueOf(startDateField.getText()));
        projectPersonnelTable.setEndDate(Date.valueOf(endDateField.getText()));
        return projectPersonnelTable;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
